package com.ruoyi.alarm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.alarm.domain.AlarmDevice;
import com.ruoyi.alarm.service.IAlarmDeviceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备报警信息Controller
 * 
 * @author ruoyi
 * @date 2023-01-04
 */
@Controller
@RequestMapping("/alarm/device")
public class AlarmDeviceController extends BaseController
{
    private String prefix = "alarm/device";

    @Autowired
    private IAlarmDeviceService alarmDeviceService;

    @RequiresPermissions("alarm:device:view")
    @GetMapping()
    public String device()
    {
        return prefix + "/device";
    }

    /**
     * 查询设备报警信息列表
     */
    @RequiresPermissions("alarm:device:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AlarmDevice alarmDevice)
    {
        startPage();
        List<AlarmDevice> list = alarmDeviceService.selectAlarmDeviceList(alarmDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备报警信息列表
     */
    @RequiresPermissions("alarm:device:export")
    @Log(title = "设备报警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AlarmDevice alarmDevice)
    {
        List<AlarmDevice> list = alarmDeviceService.selectAlarmDeviceList(alarmDevice);
        ExcelUtil<AlarmDevice> util = new ExcelUtil<AlarmDevice>(AlarmDevice.class);
        return util.exportExcel(list, "设备报警信息数据");
    }

    /**
     * 新增设备报警信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备报警信息
     */
    @RequiresPermissions("alarm:device:add")
    @Log(title = "设备报警信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AlarmDevice alarmDevice)
    {
        return toAjax(alarmDeviceService.insertAlarmDevice(alarmDevice));
    }

    /**
     * 修改设备报警信息
     */
    @RequiresPermissions("alarm:device:edit")
    @GetMapping("/edit/{alarmGroup}")
    public String edit(@PathVariable("alarmGroup") String alarmGroup, ModelMap mmap)
    {
        AlarmDevice alarmDevice = alarmDeviceService.selectAlarmDeviceByAlarmGroup(alarmGroup);
        mmap.put("alarmDevice", alarmDevice);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备报警信息
     */
    @RequiresPermissions("alarm:device:edit")
    @Log(title = "设备报警信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AlarmDevice alarmDevice)
    {
        return toAjax(alarmDeviceService.updateAlarmDevice(alarmDevice));
    }

    /**
     * 删除设备报警信息
     */
    @RequiresPermissions("alarm:device:remove")
    @Log(title = "设备报警信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(alarmDeviceService.deleteAlarmDeviceByAlarmGroups(ids));
    }
}
